<template>
  <div class="app-container">
    <div class="detailsbody">
      <div class="top">商品详情
        <div class="edit" @click="headleEdit()">编辑</div>
      </div>
      <ul class="tiltes">
        <li :class="item.id===navIndex?'active':''" v-for="item in navList" :key="item.id" @click="switchTab(item)">{{item.txt}}</li>
      </ul>
      <el-card class="detail_info" style="display:flex" v-if="commodity_details">
        <div class="detail_info-item">
          <div style="display:flex">
            <span class="tilte" style="width:102px;">商品信息</span>
            <div class="line"></div>
          </div>
          <el-form ref="productInfoForm" label-width="120px" size="small" class="el-form-table">
            <el-form-item label="商品名称">
              <el-input v-model="details.name" required></el-input>
            </el-form-item>
            <el-form-item label="商品图片" required>
              <div class="tips">建议尺寸：1000*750像素，最多一张</div>
              <div class="goodsimg">
                <img :src="details.pic" alt="">
              </div>
            </el-form-item>
            <el-form-item label="商品展示图" required>
              <div class="tips">建议尺寸：160*160像素，最多1张</div>
              <div class="showcaseimg">
                <img :src="details.picSquare" alt="">
              </div>
            </el-form-item>
            <el-form-item label="商品价格">
              <el-input v-model="details.price" required placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item label="商品库存">
              <el-input v-model="details.stock" required></el-input>
            </el-form-item>
            <el-form-item label="数量规格">
              <el-input v-model="details.amountSpecification" required aria-placeholder="如：320ml/32颗装等"></el-input>
            </el-form-item>
            <el-form-item label="包装规格">
              <el-input v-model="details.packSpecification" required :aria-placeholder="details.price "></el-input>
            </el-form-item>
            <el-form-item label="成本价格">
              <el-input v-model="details.costPrice"></el-input>填写成本可以帮助您统计利润数据
            </el-form-item>
            <!-- <el-form-item style="text-align: center">
              <el-button type="primary" size="medium" @click="handleNext('productInfoForm')">下一步，填写商品促销</el-button>
            </el-form-item>-->
          </el-form>
        </div>
        <div class="detail_info-item">
          <div style="display:flex">
            <span class="tilte" style="width:102px;">物流信息</span>
            <div class="line"></div>
          </div>
          <el-form>
            <div class="details_set">
              <p>
                <em>*</em>运费设置
              </p>
              <!-- 0统一邮费；1全国包邮；2本省包邮,外地统一邮费 -->
              <span v-if="details.postageType==0">
                统一邮费
                <em>{{details.postage}}</em>
                <b>元</b>
              </span>
              <span v-if="details.postageType==1">
                全国包邮
                <em>{{details.postage}}</em>
                <b>元</b>
              </span>
              <span v-if="details.postageType==2">
                本省包邮,外地统一邮费
                <em>{{details.postage}}</em>
                <b>元</b>
              </span>
            </div>
          </el-form>
        </div>
        <div class="detail_info-item">
          <div style="display:flex">
            <span class="tilte" style="width:102px;">销售说明</span>
            <div class="line"></div>
          </div>
          <el-form style="display:flex">
            <div class="details_set">
              <p>
                <em>*</em>是否可退换
              </p>
              <!-- 是否可退换：0不可退换；1可退换 -->
              <span v-if="details.isExchange==0">不可退换</span>
              <span v-if="details.isExchange==1">可退换</span>
            </div>
            <div class="details_set">
              <p>
                <em>*</em>积分使用
              </p>
              <!-- 是否可用积分：0不可用；1可用  isUseIntegral-->
              <span v-if="details.isUseIntegral==0">不可使用积分</span>
              <span v-if="details.isUseIntegral==1">可使用积分</span>
            </div>
          </el-form>
        </div>
      </el-card>
      <div v-if="commodityd_escription" style="height:610px;">
        <div class="" style="height: 500px;border:none;">
          <quill-editor v-model="details.description" ref="myQuillEditor" :options="editorOption" style="height: 450px;border:none;"></quill-editor>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { fetchList, Commoditydetails } from "@/api/product";
import { quillEditor } from "vue-quill-editor";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";

export default {
  name: "FuncFormsEdit",
  components: {
    //使用编辑器
    quillEditor
  },
  data() {
    return {
      value: Object,
      navIndex: 1, // 导航
      commodity_details: true,
      commodityd_escription: false,
      editor: null,
      content: null,
      details: Object,
      editorOption: {
        placeholder: "请输入"
        // theme: "bubble", // or 'bubble'
        // modules: {
        //   toolbar: {
        //     container: "#toolbar"
        //   }
        // }
      },
      navList: [
        {
          id: 1,
          txt: "基本信息",
          status: "1"
        },
        {
          id: 2,
          txt: "商品描述",
          status: "2"
        }
      ],
      value: {
        name: "九转黄精丸【美肤排毒】"
      }
    };
  },
  props: {
    defaultMsg: {
      type: String
    },
    config: {
      type: Object
    }
  },
  mounted() {
    // const _this = this;
    // this.editor = UE.getEditor("editor", this.config); // 初始化UE
    // this.editor.addListener("ready", function() {
    //   _this.editor.setContent(_this.defaultMsg); // 确保UE加载完成后，放入内容。
    // });
    this.getDetails();
  },
  methods: {
    switchTab(item) {
      this.navIndex = item.id;
      if (this.navIndex == 1) {
        this.commodity_details = true;
        this.commodityd_escription = false;
      } else {
        this.commodity_details = false;
        this.commodityd_escription = true;
      }
    },
    getDetails() {
      Commoditydetails(this.$route.query.id).then(response => {
        this.details = response.data;
      });
    },
    // 编辑
    headleEdit() {
      this.$router.push({
        path: "/updateProduct",
        query: { id: this.$route.query.id }
      });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.app-container {
  background: #f1f1f1;
  min-height: 500px;
  .detailsbody {
    background: #fff;
    width: 100%;
    height: 100%;
    .tiltes {
      display: flex;
      font-size: 16px;
      font-family: AlibabaPuHuiTiR;
      border-bottom: 1px solid #cccccc;
      background: transparent;
      padding-left: 20px !important;
      line-height: 48px !important;
      box-sizing: border-box;
      padding: 0 !important;
      margin: 0 !important;
      margin-bottom: 10px !important;
      cursor: pointer;
      li {
        width: 136px;
        text-align: center;
        cursor: pointer;
      }
      li.active {
        cursor: pointer;
        width: 136px;
        height: 4px;
        height: 48px;
        line-height: 48px !important;
        border-bottom: 4px solid rgba(96, 118, 255, 1);
        box-sizing: border-box;
      }
    }
    .el-card {
      box-shadow: none !important;
      border: none;
      .el-card__body {
        .detail_info-item {
          .title {
            font-size: 16px;
            width: 102px;
            font-family: AlibabaPuHuiTiM;
            color: rgba(0, 0, 0, 1);
          }
          .line {
            width: 1000px;
            height: 10px;
            border-bottom: 2px solid #f1f1f1;
            // background: #f1f1f1;
          }
          .details_set {
            padding: 20px 0px;
            box-sizing: border-box;
            width: 200px;
            margin-left: 100px;
            p {
              em {
                color: #ff0000;
                margin-right: 4px;
              }
            }
            span {
              margin-left: 4px;

              em {
                margin-right: 4px;
                font-style: normal;
              }
              b {
                color: #ccc;
              }
            }
          }
          .el-form-table {
            padding-top: 20px;
            margin-left: 80px;
            // border-top: 2px solid #f1f1f1;
            // box-sizing: border-box;
            .goodsimg {
              width: 145px;
              height: 120px;
              img {
                width: 100%;
                height: 100%;
                vertical-align: middle;
              }
            }
            .showcaseimg {
              width: 100px;
              height: 100px;
              img {
                width: 100%;
                height: 100%;
                vertical-align: middle;
              }
            }
            .tips {
              color: #999;
              font-size: 12px;
            }
          }
        }
      }
    }
  }
  .top {
    padding: 4px 25px 0;
    line-height: 48px;
    display: flex;
    height: 48px;
    justify-content: space-between;
    border-bottom: 1px solid #f1f1f1;
    box-sizing: border-box;
    .edit {
      background: #169bd5;
      color: #fff;
      width: 73px;
      height: 32px;
      line-height: 32px;
      text-align: center;
      border-radius: 4px;
      cursor: pointer;
    }
  }
}
</style>
